function Check() {
    // console.log($("#author")[0].value)
    if ($("#title")[0].value.length == 0 || $("#content")[0].value.length == 0 || $("#author")[0].value.length == 0) {
        alert("标题,正文,作者都不能为空!");
        return false
    } else {
        return true
    }
}

$(function () {
    $("#release").click(function () {
        $("#createnews").ajaxSubmit(function (data) {
            console.log(data);
            if (data["error"] === undefined && data["row"] === 1) {
                var c = confirm("发布成功,是否返回上一页?");
                if (c) {
                    window.location.href = "/"
                } else {
                    window.location.reload()
                }
                $("#title").val("");
                $("#content").val("")
            } else {
                alert("发布失败!")
            }
        });
    });

    $("#update").click(function () {
        $("#updatenews").ajaxSubmit(function (data) {
            console.log(data);
            if (data["error"] === undefined && data["row"] === 1) {
                var c = confirm("修改成功,是否返回上一页?");
                if (c) {
                    window.location.href = "/"
                } else {
                    window.location.reload()
                }
                $("#title").val("");
                $("#content").val("")
            } else {
                alert("修改公告失败!")
            }
        });
    })
});

function ChangeStatus(id, status) {
    var s = 0;
    if (status == 1) {
        s = 2
    } else {
        s = 1
    }
    $.post("news", {id: id, status: s, option: "UUU"}, function (result) {
            console.log(result);
            if (result["error"] === undefined & result["row"] === 1) {
                alert("修改成功!");
                window.location.reload()
            } else {
                alert("修改失败!")
            }
        }
    )
}

function DeleteNews(id) {
    $.post("news", {id: id, option: "DDD"}, function (result) {
        console.log(result);
        if (result["error"] === undefined & result["row"] === 1) {
            if (result["error"] === undefined & result["row"] === 1) {
                alert("删除成功!");
                window.location.reload()
            } else {
                alert("删除失败!")
            }
        }
    })
}

function loadnews(id) {
    $.post("news", {id: id, option: "RRR"}, function (result) {
        console.log(result);
        if (result["error"] === undefined) {
            $("#uid").val(result["obj"]["Id"]);
            $("#utitle").val(result["obj"]["Title"]);
            $("#ucontent").val(result["obj"]["Content"]);
            $("#uauthor").val(result["obj"]["Author"])
        } else {
            alert("读取数据失败...")
        }
    })
}

